﻿using System;
using System.Windows;
using System.Xml.Linq;

namespace DynamicGeometry
{
    public class Label : LabelBase, IMovable
    {
        public Label()
        {
            ShouldProcessText = true;
        }

        public override void ReadXml(XElement element)
        {
            base.ReadXml(element);
            text = element.ReadString("Text").Replace(@"\n", Environment.NewLine);
            var x = element.ReadDouble("X");
            var y = element.ReadDouble("Y");
            MoveTo(new Point(x, y));
        }

        public override void WriteXml(System.Xml.XmlWriter writer)
        {
            base.WriteXml(writer);
            var coordinates = Coordinates;
            writer.WriteAttributeString("Text", Text.Replace("\n", "").Replace("\r", @"\n"));
            writer.WriteAttributeString("X", coordinates.X.ToStringInvariant());
            writer.WriteAttributeString("Y", coordinates.Y.ToStringInvariant());
        }
    }
}
